package 一些笔试真题;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-10-05
 * Time: 15:05
 */

/*
    k个为一组翻转链表
 */
public class bilibili_3 {
    private static void reverse(String[] str, int start, int end){
        while(start < end){
            String tmp = str[start];
            str[start] = str[end];
            str[end] = tmp;
            start++;
            end--;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] str = s.split(" ");
        int k = scanner.nextInt();
        int start = 0;
        while(start + k - 1 < str.length - 1){
            reverse(str, start, start + k - 1);
            start += k;
        }
        for(int i = 0; i < str.length - 2; i++){
            System.out.print(str[i] + "->");
        }
        System.out.println(str[str.length - 2]);
    }
}
